package com.lzq.leetcode.alg;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Deque;
import java.util.LinkedList;

public class ST {

    public int[] dailyTemperatures(int[] temperatures) {
        int n =temperatures.length;
        int[] ret = new int[n];

        Deque<Integer> stack = new LinkedList<>();

        for (int i=n-1; i>=0; i--) {
            while ( !stack.isEmpty() && temperatures[stack.peek()] <= temperatures[i]) {
                stack.pop();
            }
            ret[i] = stack.isEmpty() ? 0 : stack.peek()-i;
            stack.push(i);
        }

        return ret;
    }


    public static void main(String[] args) {


        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

    }

}
